package cn.pugle.benchmark;

/**
 * Created by tzp on 6/3/16.<br>
 */
public class MyBenchMark implements Runnable {

    public static void main(String[] args) throws InterruptedException {
        benchmark(new MyBenchMark(), 100);
    }

    public static void benchmark(Runnable toRun, int times) throws InterruptedException {
        double aver = 0;
        double total = 0;
        for (int i = 0; i < times; i++) {
            long start = System.nanoTime();
            toRun.run();
            double l = (System.nanoTime() - start) / 1000000.0;
            aver = (aver * i + l) / (i + 1);
            total += l;
        }
        System.out.println("运行" + times + "次,平均 " + aver);
    }

    public static String replace() {
        return "a_tid_b_eid_c".replace("_tid_", String.valueOf(1))
                .replace("_eid_", String.valueOf(2));
    }

    public static String format() {
        return String.format("a%db%dc", 1, 2);
    }

    @Override
    public void run() {
//        replace();//平均0.05
//        format();//平均0.35
//        System.out.println(replacePathPlaceholder("abcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijk"));
//        System.out.println(replaceWithSubStrings("abcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijk"));
//        System.out.println(replaceWithMatcher("abcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijkabcd$##$defghd$##$ijk"));
    }
}
